home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.08 Aug 91 / Modeless SF Source / CStarterApp.p < prev    next >
Encoding:
Text File  |  1991-01-13  |  6.9 KB  |  291 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CStarterApp.p                                                                    }
  4. {}
  5. {        Application methods for a typical application.                                    }
  6. {}
  7. {        Copyright © 1989, Symantec Corporation.  All rights reserved.            }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. UNIT CStarterApp;
  13.  
  14. INTERFACE
  15.  
  16. USES
  17.     TCL, CSFDialogs, StarterIntf;
  18.  
  19. IMPLEMENTATION
  20.  
  21.  
  22. {**}
  23. { * IStarterApp}
  24. { *}
  25. { *    Initialize the application. Your initialization method should}
  26. { *    at least call the inherited method. If your application class}
  27. { *    defines its own instance variables or global variables, this}
  28. { *    is a good place to initialize them.}
  29. { *}
  30. { **}
  31.  
  32. PROCEDURE CStarterApp.IStarterApp;
  33.  
  34.     BEGIN
  35.         ICSFApplication(4, 20480, 2048);
  36.  
  37.         { The parameters to IApplication are the number of times to call MoreMasters,    }
  38.         { the number of bytes of heap space to reserve for monitoring                        }
  39.         { low memory situations, and the credit limit for memory requests.                }
  40.         {   Four (4) is a reasonable number of MoreMasters calls,                            }
  41.         { but you should determine a good number for your application                        }
  42.         { by observing the heap using Lightsbug,                                                }
  43.         { TMON, or Macsbug. Set this parameter to zero, give your                            }
  44.         { program a rigorous work-out, then look at the heap and count                        }
  45.         { how many master pointer blocks have been allocated. Master                        }
  46.         { pointer blocks are nonrelocatable and have a size of $100                            }
  47.         { (hex). You should call MoreMasters at least this many                                }
  48.         { times -- add a few extra just to be safe. The purpose of all                        }
  49.         { this preflighting is to prevent heap fragmentation. You                                }
  50.         { don't want the Memory Manager to call MoreMasters and                            }
  51.         { create a nonrelocatable block in the middle of your heap. By                        }
  52.         { calling MoreMasters at the very beginning of the program,                            }
  53.         { you ensure that these blocks are allocated in a group at the                        }
  54.         { bottom of the heap.                                                                        }
  55.         {   The memory reserve is a safeguard for handling low memory                    }
  56.         { conditions and is used by the GrowMemory method in                                }
  57.         { CApplication (check there for more comments). In general,                            }
  58.         { your program should never request a memory block greater                        }
  59.         { than this reserve size without explicitly checking in                                }
  60.         { advance whether there is enough free memory to satisfy the                        }
  61.         { the request.                                                                                }
  62.         {   The credit limit specifies a cut-off level for memory                                }
  63.         { requests which can tap the memory reserve. Requests larger                        }
  64.         { than this size will not use the memory reserve when the                            }
  65.         { system pleads for more memory.                                                        }
  66.  
  67.     END;
  68.  
  69.  
  70.  
  71. {**}
  72. { * SetUpFileParameters}
  73. { *}
  74. { *    In this routine, you specify the kinds of files your}
  75. { *    application opens.}
  76. { *}
  77. { **}
  78.  
  79. PROCEDURE CStarterApp.SetUpFileParameters;
  80.  
  81.     BEGIN
  82.  
  83.         INHERITED SetUpFileParameters;    { Be sure to call the default method }
  84.  
  85.         {*}
  86. {         **    sfNumTypes is the number of file types}
  87. {         **    your application knows about.}
  88. {         **    sfFileTypes[] is an array of file types.}
  89. {         **    You can define up to 4 file types in}
  90. {         **    sfFileTypes[].}
  91. {         **}
  92. {         *}
  93.  
  94.         sfNumTypes := 1;
  95.         sfFileTypes[0] := 'TEXT';
  96.  
  97.         {*}
  98. {         **    Although it's not an instance variable,}
  99. {         **    this method is a good place to set the}
  100. {         **    gSignature global variable. Set this global}
  101. {         **    to your application's signature. You'll use it}
  102. {         **    to create a file (see CFile.CreateNew).}
  103. {         **}
  104. {         *}
  105.  
  106.         gSignature := '????';
  107.     END;
  108.  
  109.  
  110.  
  111. {**}
  112. { * SetUpMenus }
  113. { *}
  114. { * Set up menus which must be created at run time, such as a}
  115. { * Font menu. You can eliminate this method if your application}
  116. { * does not have any such menus.}
  117. { *}
  118. {**}
  119.  
  120. PROCEDURE CStarterApp.SetUpMenus;
  121.     BEGIN
  122.  
  123.         INHERITED SetUpMenus;            { Superclass takes care of adding        }
  124.                                         {   menus specified in a MBAR id = 1    }
  125.                                         {   resource                                }
  126.  
  127.         { Add your code for creating run-time menus here    }
  128.     END;
  129.  
  130.  
  131. {**}
  132. { * DoCommand}
  133. { *}
  134. { *    Your application will probably handle its own commands.}
  135. { *    Remember, the command numbers from 1-1023 are reserved.}
  136. { *    The file TCL.p contains all the predefined TCL commands.}
  137. { *}
  138. { *    Be sure to call the default method, so you can get}
  139. { *    the default behavior for standard commands.}
  140. { *}
  141. { **}
  142.  
  143. PROCEDURE CStarterApp.DoCommand (theCommand: longint);
  144.  
  145.     VAR
  146.         aCSFGetDialog: CSFGetDialog;
  147.         aCSFSaveDialog: CSFSaveDialog;
  148.  
  149.     BEGIN
  150.  
  151.         CASE theCommand OF
  152.  
  153.             CSFOpenCmd: 
  154.                 BEGIN
  155.                     New(aCSFGetDialog);
  156.                     aCSFGetDialog.ICSFDialog
  157.                 END;
  158.  
  159.             CSFSaveCmd: 
  160.                 BEGIN
  161.                     New(aCSFSaveDialog);
  162.                     aCSFSaveDialog.ICSFDialog
  163.                 END;
  164.  
  165.             OTHERWISE                                        { Invoke inherited method     }
  166.                 INHERITED DoCommand(theCommand);        { to handle other commands    }
  167.  
  168.         END;
  169.     END;
  170.  
  171.  
  172. {**}
  173. { *}
  174. { * UpdateMenus }
  175. { *}
  176. { *     Perform menu management tasks}
  177. { *}
  178. {**}
  179.  
  180. PROCEDURE CStarterApp.UpdateMenus;
  181.     BEGIN
  182.  
  183.         INHERITED UpdateMenus;            { Enable standard commands            }
  184.  
  185.         gBartender.EnableCmd(CSFOpenCmd);
  186.         gBartender.EnableCmd(CSFSaveCmd);
  187.  
  188.         { Enable the commands handled by your Application class    }
  189.     END;
  190.  
  191.  
  192. {**}
  193. { * Exit}
  194. { *}
  195. { *    Chances are you won't need this method.}
  196. { *    This is the last chance your application gets to clean up}
  197. { *    things like temporary files before terminating.}
  198. { *}
  199. { **}
  200.  
  201. PROCEDURE CStarterApp.Exit;
  202.  
  203.     BEGIN
  204.     { your exit handler here }
  205.     END;
  206.  
  207.  
  208. {**}
  209. { * CreateDocument}
  210. { *}
  211. { *    The user chose New from the File menu.}
  212. { *    In this method, you need to create a document and send it}
  213. { *    a NewFile message.}
  214. { *}
  215. { **}
  216.  
  217. PROCEDURE CStarterApp.CreateDocument;
  218.  
  219.     VAR
  220.         theDocument: CStarterDoc;
  221.  
  222.     BEGIN
  223.  
  224.         new(theDocument);
  225.  
  226.         {*}
  227. {         **    Send your document an initialization}
  228. {         **    message. The first argument is the document's}
  229. {         **    supervisor (the application). The second}
  230. {         **    argument is TRUE if the document is printable.}
  231. {         **}
  232. {         *}
  233.  
  234.         theDocument.IStarterDoc(SELF, TRUE);
  235.  
  236.         {*}
  237. {         **    Send the document a NewFile message.}
  238. {         **    The document will open a window, and}
  239. {         **    set up the heart of the application.}
  240. {         **}
  241. {         *}
  242.  
  243.         theDocument.NewFile;
  244.     END;
  245.  
  246.  
  247. {**}
  248. { * OpenDocument}
  249. { *}
  250. { *    The user chose Open… from the File menu.}
  251. { *    In this method you need to create a document}
  252. { *    and send it an OpenFile message.}
  253. { *}
  254. { *    The macSFReply is a good SFReply record that contains}
  255. { *    the name and vRefNum of the file the user chose to}
  256. { *    open.}
  257. { *}
  258. { **}
  259.  
  260. PROCEDURE CStarterApp.OpenDocument (macSFReply: SFReply);
  261.  
  262.     VAR
  263.         theDocument: CStarterDoc;
  264.  
  265.     BEGIN
  266.  
  267.         new(theDocument);
  268.  
  269.         {*}
  270. {         **    Send your document an initialization}
  271. {         **    message. The first argument is the document's}
  272. {         **    supervisor (the application). The second}
  273. {         **    argument is TRUE if the document is printable.}
  274. {         **}
  275. {         *}
  276.  
  277.         theDocument.IStarterDoc(SELF, TRUE);
  278.  
  279.         {*}
  280. {         **    Send the document an OpenFile message.}
  281. {         **    The document will open a window, open}
  282. {         **    the file specified in the macSFReply record,}
  283. {         **    and display it in its window.}
  284. {         **}
  285. {         *}
  286.  
  287.         theDocument.OpenFile(macSFReply);
  288.     END;
  289.  
  290.  
  291. END.